//
//  LYArtHeaderViewController.m
//  artist
//
//  Created by Jay_Apple on 16/3/3.
//  Copyright © 2016年 viviyoo. All rights reserved.
//

#import "LYArtHeaderViewController.h"
#import "LYCircleListModel.h"
#import "LYMineFriendsController.h"
#import "XMGInfiniteScrollView.h"
#import "LYStuWebViewController.h"


@interface LYArtHeaderViewController ()
@property (weak, nonatomic) IBOutlet UIButton *circleBtn;
@property (weak, nonatomic) IBOutlet XMGInfiniteScrollView *bannerViews;
@property (nonatomic, strong) NSArray *models;
@end

@implementation LYArtHeaderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self getBanner];
    
    //初始化圈子信息
    [self setUpCircleComponent];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 初始化
- (void)setUpCircleComponent{

    
    if (self.model.is_circle_user) {
        [self.circleBtn setTitle:@"退出圈子" forState:UIControlStateNormal];
    }else{
    
        [self.circleBtn setTitle:@"加入圈子" forState:UIControlStateNormal];
    }
}



#pragma mark - 网络请求

- (void)getBanner{
    
    [LYRequestTool getSlideImageWithToken:LYToken slide_type:LYSlideTypeErtist success:^(NSArray<LYBannerModelModel *> *models) {
        
        
        self.models = models;
        
    } failure:^(NSString *code, NSString *message) {
        
    }];
    
}

#pragma mark - 重写方法
- (void)setModels:(NSArray *)models{
    
    _models = models;
    
    self.bannerViews.models = _models;
    
}


/**
 *  加入圈子
 */
- (void)joinCircleWithCircleID:(NSString *)circleID{
    
    [MBProgressHUD showMessage:nil];
    [LYRequestTool joinCircleListWithToken:LYToken circle_id:circleID success:^{
        
        [MBProgressHUD hideHUD];
        [MBProgressHUD showOnlyText:@"加入圈子成功"];
        self.model.is_circle_user = YES;
        [self setUpCircleComponent];
        
    } failure:^(NSString *code, NSString *message) {
       
        [MBProgressHUD hideHUD];
        [MBProgressHUD showOnlyText:message];
        
    }];

}

/**
 *  退出圈子
 */
- (void)quitCircleWithCircleID:(NSString *)circleID{
    
    [MBProgressHUD showMessage:nil];
    [LYRequestTool exitCircleListWithToken:LYToken circle_id:circleID success:^{
        
        [MBProgressHUD hideHUD];
        [MBProgressHUD showOnlyText:@"退出圈子成功"];
        self.model.is_circle_user = NO;
        [self setUpCircleComponent];
        
    } failure:^(NSString *code, NSString *message) {
        [MBProgressHUD hideHUD];
        [MBProgressHUD showOnlyText:message];
    }];

}
#pragma mark - 按钮点击

- (IBAction)friendBtnOnclick:(id)sender {
    
    [[VVYCheckStatus sharedInstance] checkIsLoginBlock:^(LYUserInfoModel *model) {
        
        LYMineFriendsController *friendVC = [[LYMineFriendsController alloc] init];
        friendVC.navigationItem.title = @"我的艺友";
        [self.navigationController pushViewController:friendVC animated:YES];
        
    }];
    
    
    
}

- (IBAction)circleBtnOnclick:(id)sender {

    [[VVYCheckStatus sharedInstance] checkIsLoginBlock:^(LYUserInfoModel *model) {
        if (self.model.is_circle_user) {
            [self quitCircleWithCircleID:self.model.circle_id];
        }else{
            
            [self joinCircleWithCircleID:self.model.circle_id];
        }

    }];
    

}

- (IBAction)webBtnOnclick:(id)sender {
    
    [[VVYCheckStatus sharedInstance] checkIsLoginBlock:^(LYUserInfoModel *model) {
        
        
        LYStuWebViewController *webVC = [LYStuWebViewController stuWebVCWithID:model.chat_info.user_id];
        [self.navigationController pushViewController:webVC animated:YES];
    }];

    
}


@end
